from django.db import models

# Create your models here.
class Cate(models.Model):
    """
    商品分类
    """
    name = models.CharField("商品类别", max_length=30)
    # 自关联： 自己关联自己，一级类别
    # related_name 反向查询的表名
    cid = models.ForeignKey('self', related_name='subs', on_delete=models.CASCADE, null=True, blank=True)

    class Meta:
        db_table = 'cate'
        verbose_name_plural = "商品分类"
    def __str__(self):
        return self.name
class Group(models.Model):
    """
    分类分组
    """
    name = models.CharField("分类分组", max_length=30)
    # 一级类别
    cate = models.OneToOneField(Cate, on_delete=models.CASCADE)
    group_url = models.CharField("频道的地址链接", max_length=100, default="http://jd.com")
    sequence = models.IntegerField(verbose_name="组内的顺序", default=0)
    class Meta:
        db_table = 'cate_group' # 不能使用group命名，会导致sql操作失败。

    def __str__(self):
        return self.name